<template>
  <transition name="slide">
    <music-list :title="title" :bgImage="bgImage" :songs="songs"></music-list>
  </transition>
</template>

<script>
import MusicList from '@/components/common/MusicList'
import { mapState } from 'vuex'
export default {
  components: {
    MusicList
  },
  data () {
    return {
      songs: [] // 歌曲列表
    }
  },
  methods: {
    // 检查是否存在songList对象
    checkAlbum () {
      if (!this.album.albumMiD) {
        // 不存在时 刷新返回
        this.$router.back()
      }
    },
    // 获取歌手热门专辑
    async getAlbum () {
      // 出现加载效果
      this.songs = []
      const { data: res } = await this.$http.get('api/album/songs?albummid=' + this.album.albumMID)

      // 成功
      if (res.result === 100) {
        this.songs = res.data.list
      } else {
        console.log('获取失败')
      }
    }
  },
  computed: {
    ...mapState(['album']),
    title () {
      return this.album.title
    },
    bgImage () {
      return this.album.cover
    }
  },
  mounted () {
    this.getAlbum()
    this.checkAlbum()
  },
  watch: {
    album () {
      this.getAlbum()
    }
  }
}
</script>

<style lang="stylus" scoped>
.slide-enter, .slide-leave-to {
  transform: translate3d(100%, 0, 0);
}
.slide-enter-active, .slide-leave-active {
  transition: all 0.3s;
}
</style>
